﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RsaRegister.Model;
using SoftRegManager.Model;using SqlSugar;

namespace SoftRegManager.BLL
{
    public partial class GreatBLL
    {
        public ISugarQueryable<SoftInfo> GetSoftwareInfoes()
        {
            return mDbClient.Queryable<SoftInfo>();
        }
        public SoftInfo GetSoftwareInfo(Guid id)
        {
           return GetSoftwareInfoes().Single(s => s.SoftId == id);
        }
        /// <summary>
        /// 根据软件名称来查找软件的RSA信息。如果查到多于一条，会抛异常
        /// </summary>
        /// <param name="softName"></param>
        /// <returns></returns>
        public SoftInfo GetSoftwareInfo(string softName)
        {
            return GetSoftwareInfoes().Single(s => s.SoftName == softName);
        }
        /// <summary>
        /// 保存软件RSA信息，并返回成功保存的实例
        /// </summary>
        /// <param name="softwareInfo"></param>
        /// <returns></returns>
        public SoftInfo SaveSoftwareInfo(SoftInfo softwareInfo)
        {
            if (softwareInfo.SoftId == Guid.Empty) softwareInfo.SoftId = Guid.NewGuid();
            softwareInfo.LastUpdated = mDbClient.GetDate();
            return mDbClient.Saveable(softwareInfo).ExecuteReturnEntity();
        }
        public int SaveSoftwareInfoes(List<SoftInfo> softwareInfos)
        {
            return mDbClient.Saveable(softwareInfos).ExecuteCommand();
        }
        public bool DeleteSoftwareInfo(Guid softId)
        {
            return mDbClient.Deleteable<SoftInfo>(s => s.SoftId == softId).ExecuteCommand() > 0;
        }
    }
}
